<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ExportController
 *
 * @author urech
 */
class ExportController extends Controller {

	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout = '//layouts/column2';

	/**
	 * @return array action filters
	 */
	public function filters() {
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules() {
		return array(
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions' => array('excel', 'excelOld'),
				'roles' => array('sektion'),
			),
			array('deny', // deny all users
				'users' => array('*'),
			),
		);
	}

	public function actionExcel() {
		$model = new Member('search');
		
		$model->unsetAttributes();  // clear any default values
		if (isset($_GET['Member']))
			$model->attributes = $_GET['Member'];
		
		$this->widget('EExcelView', array(
			'id' => 'JUSO_Excel_Export',
			'dataProvider' => $model->export(),
			'filter' => $model,
			'title' => 'ExportJUSO',
			'filename' => date('ymd') . '_Mitglieder',
			'exportType' => 'Excel2007',
			'disablePaging' => true,
			'grid_mode' => 'export',
			'columns' => array(
				array('name' => 'OM-Nummer', 'header' => 'OM-Nummer', 'value' => '$data->membership->Kundennummer'),
				array('name' => 'Anrede', 'value' => '$data->profileExtensions->Adressblock_Zeile_1'),
				'Vorname',
				'Name',
				array('name' => 'Strasse_mit_HNR', 'header' => 'Strasse_mit_HNR', 'value' => '$data->Strasse . " " . $data->Hausnummer . " " . $data->Hausnummer_Zusatz'),
				'PLZ',
				'Ortschaft',
				'Land',
				'Telefon_Privat',
				'Telefon_Geschaeft',
				'Mobile',
				'Email',
				'Sprache',
				'Geschlecht',
				array('name' => 'Briefanrede', 'value' => '$data->profileExtensions->Briefanrede'),
				array('name' => 'Geburtsdatum', 'value' => 'date("d.m.Y", strtotime($data->Geburtsdatum))'),
				array('name' => 'Sektion', 'value' => '$data->membership->Mitgliederbezeichnung'),
				array('name' => 'Status', 'value' => '$data->membership->Klasse_Verband'),
			)
		));
	}

	public function actionExcelOld() {
		$model = new Member('search');
		$this->widget('EExcelView', array(
			'id' => 'JUSO_Excel_Export',
			'dataProvider' => $model->export(true),
			'filter' => $model,
			'title' => 'ExportJUSO',
			'filename' => date('ymd') . '_Mitglieder',
			'exportType' => 'Excel2007',
			'disablePaging' => true,
			'grid_mode' => 'export',
			'columns' => array(
				array('name' => 'OM-Nummer', 'header' => 'OM-Nummer', 'value' => '$data->membership->Kundennummer'),
				array('name' => 'Anrede', 'value' => '$data->profileExtensions->Adressblock_Zeile_1'),
				'Vorname',
				'Name',
				array('name' => 'Strasse_mit_HNR', 'header' => 'Strasse_mit_HNR', 'value' => '$data->Strasse . " " . $data->Hausnummer . " " . $data->Hausnummer_Zusatz'),
				'PLZ',
				'Ortschaft',
				'Land',
				'Telefon_Privat',
				'Telefon_Geschaeft',
				'Mobile',
				'Email',
				'Sprache',
				'Geschlecht',
				array('name' => 'Briefanrede', 'value' => '$data->profileExtensions->Briefanrede'),
				array('name' => 'Geburtsdatum', 'value' => 'date("d.m.Y", strtotime($data->Geburtsdatum))'),
				array('name' => 'Eintritt', 'value' => 'date("d.m.Y", strtotime($data->membership->Eintritt))'),
				array('name' => 'Austritt', 'value' => 'date("d.m.Y", strtotime($data->membership->Austritt))'),
				array('name' => 'Sektion', 'value' => '$data->membership->Mitgliederbezeichnung'),
				array('name' => 'Status', 'value' => '$data->membership->Klasse_Verband'),
			)
		));
	}

}

?>
